#ifndef _SEVEN_BUS_PACKET_H
#define _SEVEN_BUS_PACKET_H

#include <stdint.h>
#include "seven_bus.h"

#ifdef __cplusplus
extern "C" {
#endif


//Frame layout
//ID(1 byte) + len(1 byte) + magic(0x5A 1 bytes) + check_sum(1 byte) + data(n bytes, max 255) + crc16(2 bytes)

#define SEVENBUS_PACKET_MAX_SIZE  (255 + 6 + 3)  //4 bytes align

#define SEVENBUS_PKT_HDR_MAGIC  (0x5A)

typedef struct {
    uint8_t id;
    uint8_t len;
    uint8_t magic; //magic number 0x5A
    uint8_t hdr_sum; //sum of header
}seven_bus_pkt_hdr_t;

typedef struct {
    seven_bus_pkt_hdr_t header;
    uint8_t data[0];
}seven_bus_pkt_t;

void seven_bus_pkt_buff_init(void);
int seven_bus_pkt_buff_rx(seven_bus_dev_t *dev, uint8_t data);


#ifdef __cplusplus
}
#endif

#endif
